<?php

/**
 * @package Framework03
 * @author Walter Tamboer
 */

/**
 * The abstract base class for database connections.
 */
abstract class DatabaseConnection
{
	/**
	 * @var string The hostname to connect to.
	 */
	protected $Hostname;
	/**
	 * @var string The username to connect with.
	 */
	protected $Username;
	/**
	 * @var string The password to connect with.
	 */
	protected $Password;
	/**
	 * Initializes a new instance of this class.
	 * @param string $Hostname The hostname to connect to.
	 * @param string $Username The username to connect with.
	 * @param string $Password The password to connect with.
	 */
	public function __construct($Hostname, $Username, $Password)
	{
		$this->Hostname = $Hostname;
		$this->Username = $Username;
		$this->Password = $Password;
	}
	/**
	 * Connects to the host.
	 */
	abstract public function Connect();
	/**
	 * Closes the connection with the host.
	 */
	abstract public function Disconnect();
	/**
	 * Selects a database according to the given name.
	 * @param string $Name The name of the database to select.
	 */
	abstract public function Select($Name);
	/**
	 * Executes a query on the server.
	 * @param string $Sql The SQL query to executes.
	 * @return DatabaseResult Returns a DatabaseResult object or null if the query failed.
	 */
	abstract public function Query($Sql);
	/**
	 * Creates a safe integer from the given input.
	 * @param int $Input The input to escape.
	 * @return int Returns the escaped integer.
	 */
	abstract public function EscapeInteger($Input);
	/**
	 * Creates a safe string from the given input.
	 * @param string $Input The input to escape.
	 * @return string Returns the escaped string.
	 */
	abstract public function EscapeString($Input);
	/**
	 * Gets the connection handle.
	 * @return Returns the connection pointer.
	 */
	abstract public function GetHandle();
}

/**
 * A abstract base class for database results.
 */
abstract class DatabaseResult
{
	/**
	 * @var DatabaseConnection Pointer to the DatabaseConnection
	 */
	protected $Connection;
	/**
	 * @var string The query that belongs to this result.
	 */
	protected $Query;
	/**
	 * Initializes a new instance of this class.
	 * @param DatabaseConnection The connection that belongs to this result.
	 * @param resource The query that was executed to get this result.
	 */
	public function __construct($Connection, $Query)
	{
		$this->Connection = $Connection;
		$this->Query = $Query;
	}
	/**
	 * Gets a row from the database.
	 * @return object Returns an object with the result.
	 */
	abstract public function Fetch();
	/**
	 * Gets the selected rows.
	 * @return int Returns an integer with the amount of selected rows.
	 */
	abstract public function Size();
	/**
	 * Gets the last inserted ID.
	 * @return int Returns an integer with the last inserted ID.
	 */
	abstract public function GetInsertID();
}

?>